/**
 * Created by YuGuo on 2016/12/1.
 */
$(function () {
    //////背景轮播图
    //var curIndex=0;//设置当前的index
    //var autoChange=setInterval(function(){
    //    if(curIndex< $('.background_pic li').length-1){
    //        curIndex++;
    //    }else{
    //        curIndex=0;
    //    }
    //    changeTo(curIndex);
    //},3000);
    ////change函数切换
    //function changeTo(num){
    //    $(".background_pic").find("li").removeClass("imgOn").hide().eq(num).fadeIn().addClass("imgOn");
    //}


    var i = 0;
    setInterval(function () {
        $(".background ul li:eq(" + i + ")").animate({opacity: 0.2}, 2000);
        i++;
        i = i % $(".background ul li").length;
        $(".background ul li:eq(" + i + ")").animate({opacity: 1}, 2000);
    }, 2000);

    //登录按钮
    $('#btn').on('click', function () {
        //var data = $("#f").serialize();
        //console.log(data);
        var un = $('#username').val();

        var pw = $('#password').val();

        if (un === '') {
            $('#msg').text("请输入账号").css("display", "block");
            return;
        }
        if (pw.length <= 0) {
            $('#msg').text('请输入密码').css("display", "block");
            return;
        }

        $.ajax({
            type:'post',
            url:'http://172.27.35.1:8888/account/login',
            data:{username:un,password:pw},
            //data:$('#a').serialize()
            dataType:'json',
            success:function(data){
                console.log(data);
                if(data.code===1){
                    console.log(data.code);
                    $('#msg').text("登录成功").css("display", "block");
                    setTimeout(function(){
                        window.location.href="./backstage.html";
                    },100)

                }else if(data.code===0){
                    $('#msg').text("登录失败").css("display", "block");
                }
            },
            error:function(){
                alert('错误');
                 }
            })
    })
});